Skip to content

Add flat start option for Newton-Raphson power flow - #1607

Open
m-mirz wants to merge 7 commits into
PowerGridModel:mainfrom
m-mirz:feature/newton-raphson-flat-start
Open

m-mirz wants to merge 7 commits into
PowerGridModel:mainfrom
m-mirz:feature/newton-raphson-flat-start

Conversation

@m-mirz

@m-mirz m-mirz commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

The linear voltage guess that Newton-Raphson starts from can make it diverge on meshed transmission grids that a flat start solves. The new power_flow_initialization option selects the start: linear (default, unchanged) or flat. See the new Initialization section in docs/algorithms/pf-algorithms.md for details.

  • C API: PGM_PowerFlowInitialization and PGM_set_power_flow_initialization, plus the C++ wrapper setter.
  • Python: PowerFlowInitialization enum; calculate_power_flow accepts power_flow_initialization as the enum or its name.
  • Tests: C++ solver tests for the flat start, including a voltage regulator case; Python test for each option value.

Partially fixes #1595 and should be merged and rebased after #1610

Relates to #549

@mgovers mgovers left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clear and good suggestion!

A couple small suggestions (mostly repetitive).

Given the impact on the C API, let's also have someone else have a look at it.

Comment thread docs/algorithms/pf-algorithms.md
Comment thread power_grid_model_c/power_grid_model/include/power_grid_model/common/enum.hpp Outdated
Comment thread power_grid_model_c/power_grid_model/include/power_grid_model/common/enum.hpp Outdated
Comment thread power_grid_model_c/power_grid_model_c/include/power_grid_model_c/options.h Outdated
Comment thread power_grid_model_c/power_grid_model_c/include/power_grid_model_c/options.h Outdated
Comment thread power_grid_model_c/power_grid_model_c/src/model.cpp Outdated
Comment thread power_grid_model_c/power_grid_model_c/src/model.cpp Outdated
Comment thread src/power_grid_model/_core/enum.py Outdated
@mgovers mgovers added the feature New feature or request label Sep 28, 2026
@TonyXiang8787

Copy link
Copy Markdown
Member

Hi @m-mirz,

Nice that you have discovered this problem. I would like to first start with a validation case.

It would be nice if you can re-produce a minimal validation meshed case where:

  • network is meshed
  • diverges in current PGM NRPF (due to the linear power flow as starting condition)
  • can converge in pandapower or matpower
  • mark the validation case as xfail, see some xfail examples in the existing validaiton case.

Please first create a separate PR for this, we can then first merge the validation case.

@Jerry-Jinfeng-Guo

Copy link
Copy Markdown
Member

Hi @m-mirz , next to what @TonyXiang8787 asked in his comment, we are also curious if the validation case could show that the linear method produces results that are indeed far away from the real solution to the extent that NR iterations diverge. We ask because by varying the starting point between said point and the real solution, we should be able to see a behavioral change if everything else is workign as they should.

@m-mirz

m-mirz commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@TonyXiang8787 I have added #1610 to show where NR does not converge from a linear start.
Of course, increasing sk also improves the results in terms of reproducing matpower since the source behaves closer to an ideal source. If sk is sufficiently large, it even fixes convergence for the matpower case118 but for none of the larger cases. Starting from case300+, only a flat start let's NR converge.

When #1610 is merged, I would rebase this one here.

@TonyXiang8787

Copy link
Copy Markdown
Member

@TonyXiang8787 I have added #1610 to show where NR does not converge from a linear start. Of course, increasing sk also improves the results in terms of reproducing matpower since the source behaves closer to an ideal source. If sk is sufficiently large, it even fixes convergence for the matpower case118 but for none of the larger cases. Starting from case300+, only a flat start let's NR converge.

When #1610 is merged, I would rebase this one here.

Hi @m-mirz, the other one is already merged and I have done a down merge for this PR.

In this PR you can remove the xfail and the test should pass.

@m-mirz

m-mirz commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

@TonyXiang8787 as mentioned in #1610, it looks like the merge was not triggered yet since my GPG signature was missing on the commit. I fixed it and now I am waiting for #1610 to get merged.

The linear voltage guess that Newton-Raphson starts from can make it
diverge on meshed transmission grids that a flat start solves. The new
power_flow_initialization option selects the start: linear (default,
unchanged) or flat. See the new Initialization section in
docs/algorithms/pf-algorithms.md for details.

- C API: PGM_PowerFlowInitialization and
  PGM_set_power_flow_initialization, plus the C++ wrapper setter.
- Python: PowerFlowInitialization enum; calculate_power_flow accepts
  power_flow_initialization as the enum or its name.
- Tests: C++ solver tests for the flat start, including a voltage
  regulator case; Python test for each option value.

Signed-off-by: Markus Mirz <16180422+m-mirz@users.noreply.github.com>
The MATPOWER IEEE 300-bus case converges from a flat start but diverges
from the linear start, also with a stiff source. The case is added twice,
with power_flow_initialization flat and linear; the linear one is marked
xfail with IterationDiverge. The expected output is the MATPOWER power
flow solution; see the case README for source and conversion.

- Python and C++ validation tests read power_flow_initialization from
  params.json.
- IterationDiverge can be named in xfail/raises of Python validation
  cases.

Signed-off-by: Markus Mirz <16180422+m-mirz@users.noreply.github.com>
@m-mirz
m-mirz force-pushed the feature/newton-raphson-flat-start branch from 8c150ff to 5ae220b Compare September 29, 2026 20:45
@m-mirz

m-mirz commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Now that #1610 is merged, I have rebased and GPG signed the commits. I have also removed the xfail test so that only the passing test remains.

The flat-start case now covers the MATPOWER IEEE 300-bus system, so the
xfail linear-start case is removed and the flat-start case moves up to
the case directory. The README keeps the note that Newton-Raphson
diverges from the linear start on this case.

Signed-off-by: Markus Mirz <16180422+m-mirz@users.noreply.github.com>
@TonyXiang8787

Copy link
Copy Markdown
Member

Now that #1610 is merged, I have rebased and GPG signed the commits. I have also removed the xfail test so that only the passing test remains.

Hi, please address the comments (especially the naming decision) from @mgovers. Then ping @mgovers and myself, we can then start CI.

Generalize the Newton-Raphson start option so it can be reused by other
calculation types and methods:

- PowerFlowInitialization -> CalculationInitialization (C++, C API, Python)
- power_flow_initialization -> calculation_initialization (options,
  PGM_set_calculation_initialization, Python keyword argument)
- add a `default` value (0) that selects the default initialization of
  the calculation method (linear for Newton-Raphson); flat = 1, linear = 2
- `default` is a C++ keyword, so the C++ enumerator is named
  default_initialization, following CalculationMethod::default_method

Signed-off-by: Markus Mirz <16180422+m-mirz@users.noreply.github.com>
@m-mirz
m-mirz force-pushed the feature/newton-raphson-flat-start branch from 3b2d3c1 to 43ceea9 Compare September 30, 2026 18:25
@m-mirz

m-mirz commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@TonyXiang8787 and @mgovers I have accepted your changes and also applied similar changes in a few more places to make sure it is consistent.

m-mirz and others added 2 commits September 30, 2026 22:00
Use the source reference angle in the flat start.

Signed-off-by: Markus Mirz <16180422+m-mirz@users.noreply.github.com>
@TonyXiang8787

Copy link
Copy Markdown
Member

Hi @m-mirz,

Thanks for the update. Please fix the build errors, and then I think the PR is in good shape.

Signed-off-by: Markus Mirz <16180422+m-mirz@users.noreply.github.com>
@m-mirz
m-mirz force-pushed the feature/newton-raphson-flat-start branch from 88e39a1 to b01f5cc Compare October 1, 2026 18:41
@m-mirz

m-mirz commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

@TonyXiang8787 I think that I've just fixed the CI issues but CI checks are awaiting approval.

@TonyXiang8787

Copy link
Copy Markdown
Member

HI @m-mirz,

Thanks again for your contribution. The PR should be ready to go. Since this PR adds new C-API changes, I have added do-not-merge label to prevent PR merging on Friday.

We will merge on Monday. Have a nice weekend!

@TonyXiang8787 TonyXiang8787 added the do-not-merge This should not be merged temporarily label Oct 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge This should not be merged temporarily feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Support matpower and CGMES transmission grid examples

5 participants